package cn.superchart.module.user.controller;

import cn.superchart.common.base.BaseController;
import cn.superchart.common.base.BaseResult;
import cn.superchart.module.role.param.ScRoleAssignParam;
import cn.superchart.module.role.param.ScRoleEditParam;
import cn.superchart.module.user.param.*;
import cn.superchart.module.user.service.ScUserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Validated
public class ScUserController extends BaseController<ScUserService> {



    @PostMapping("/sc/user/page")
    public BaseResult<Page<ScUserDetailParam>> page(@RequestBody @Valid ScUserPageParam userPageParam) {
        Page<ScUserDetailParam> page = service.page(userPageParam);
        return BaseResult.result(page);
    }


    @PostMapping("/sc/user/add")
    public BaseResult<String> add(@RequestBody @Valid ScUserAddParam scUserAddParam) {
        service.add(scUserAddParam);
        return BaseResult.ok();
    }

    @PostMapping("/sc/user/edit")
    public BaseResult<String> edit(@RequestBody @Valid ScUserEditParam scUserEditParam) {
        service.edit(scUserEditParam);
        return BaseResult.ok();
    }

    @GetMapping("/sc/user/detail")
    public BaseResult<ScUserDetailParam> detail( @Valid ScUserIdParam scUserIdParam) {
        return BaseResult.result(service.detail(scUserIdParam.getId()));
    }

    @PostMapping("/sc/user/register")
    public BaseResult<Boolean> register(@RequestBody @Valid ScUserRegisterParam scUserRegisterParam) {
        Boolean res = service.register(scUserRegisterParam);
        return BaseResult.result(res);
    }

    @GetMapping("/sc/user/getUserInfo")
    public BaseResult<ScUserDetailParam> getUserInfo() {
        return BaseResult.result(service.getUserInfo());
    }


    @DeleteMapping("/sc/user/delete")
    public BaseResult<Boolean> delete(@Valid ScUserIdParam scUserIdParam) {
        Boolean res = service.delete(scUserIdParam.getId());
        return BaseResult.result(res);
    }

    @PostMapping("/sc/user/unOrLock")
    public BaseResult<String> unOrLock(@RequestBody @Valid ScUserLockParam scUserLockParam) {
        service.unOrLock(scUserLockParam.getId(),scUserLockParam.getUserStatus());
        return BaseResult.ok();
    }

    @PostMapping("/sc/user/roleAssign")
    public BaseResult<String> roleAssign(@RequestBody @Valid ScRoleAssignParam roleAssignParam) {
        service.roleAssign(roleAssignParam);
        return BaseResult.ok();
    }

    @GetMapping("/sc/user/roleIds")
    public BaseResult<List<String>> roleIds(ScUserIdParam scUserIdParam) {
        return BaseResult.result(service.roleIds(scUserIdParam.getId()));
    }

}
